<include file="Common:header"/>
<body>
	<div class="top-wrap" style="padding-top: 15px; padding-bottom:15px;">
		<div class="top-btn-group">
			<a href="<{:U('Home/Template/set_picture')}>" class="top-btn">
				上传图片
			</a>
		</div>
		<div class="title-bg">我的广告</div>
	</div>
	<div class="main-wrap" style="padding-top:10px;">
	<if condition = "!empty($adlist)">
		<foreach name="adlist" item="value">
		<div class="top-border-box" style="margin-bottom:10px;">
			<a class="blue-link text-center pd-tb-5"
			href="
			<if condition="$value['type'] == '1'">
				<{:U('Home/Template/set_picture',array('tid'=>$value['id']))}>
			<elseif condition="$value['type'] == '4'" />
				<{:U('Home/Template/set_picture',array('tid'=>$value['id']))}>
			<elseif condition="$value['type'] == '5'" />
				<{:U('Home/Template/set_picture',array('tid'=>$value['id']))}>
			<elseif condition="$value['type'] == '2'" />
				<{:U('Home/Template/video_display',array('tid'=>$value['id']))}>
			<else />
				<{:U('Home/Template/set_word',array('tid'=>$value['id']))}>
			</if>">
				<eq name="value['type']" value="1">
					<div style="width:80px; float:left;">
						<img style="width:100%; vertical-align: middle;" src="<{$value['thumb']}>" alt="<{$value['title']}>" >
					</div>
				</eq>
				<eq name="value['type']" value="4">
					<div style="width:80px; float:left;">
						<img style="width:100%; vertical-align: middle;" src="<{$value['thumb']}>" alt="<{$value['title']}>" >
					</div>
				</eq>
				<eq name="value['type']" value="5">
					<div style="width:80px; float:left;">
						<img style="width:100%; vertical-align: middle;" src="<{$value['thumb']}>" alt="<{$value['title']}>" >
					</div>
				</eq>
				<{$value['title']}><if condition="$value['status'] eq -1">&nbsp;&nbsp;<span style="color:red">该广告已禁止使用</span></if>
				<div class="clear"></div>
			</a>
			
			<div class="grey-hr"></div>
			<div class="btn-right pd-tb-5">
				<div class="type-tag"><{$type_list[$value['type']]}></div>
				<a class="btn_l" href="javascript:void(0)" data-tid ="<{$value['id']}>" onclick="delete_ad(this)">删除</a>

				<if condition="$value['type'] == '1'">
					<a class="btn_l" href="<{:U('Home/Template/set_picture',array('tid'=>$value['id']))}>">修改</a>
				<elseif condition="$value['type'] == '4'" />
					<a class="btn_l" href="<{:U('Home/Template/set_picture',array('tid'=>$value['id']))}>">修改</a>
				<elseif condition="$value['type'] == '5'" />
					<a class="btn_l" href="<{:U('Home/Template/set_picture',array('tid'=>$value['id']))}>">修改</a>
				<elseif condition="$value['type'] == '2'" />
					<a class="btn_l" href="<{:U('Home/Template/video_display',array('tid'=>$value['id']))}>">修改</a>
				<else />
					<a class="btn_l" href="<{:U('Home/Template/set_word',array('tid'=>$value['id']))}>">修改</a>
				</if>
			</div>
		</div>
		</foreach>
	<else />
		<div class="nodata-box" >还没有广告数据</div>
	</if>
		<div id="loadding" style="text-align: center; display: none;"><img src="__PUBLIC__/js/layer/skin/default/loading-0.gif" /></div>
		<input type="hidden" id="page" value="1">
	</div>


<include file="Common:menu"/>
</body>
</html>
<script>

var type_list = <?php echo json_encode($type_list); ?>;

$(function(){
	$(window).scroll(function () {
		if($(window).scrollTop()>=($(document).height()-$(window).height())){
			ajax_template();
		}
	});
});

//加载模板
function ajax_template(){
	// alert('ajax_template '+$('#page').val());
	var loadObj = $('#loadding');
	var page = $('#page').val();
	if(page == '-1'){
		return false;
	}
	loadObj.show();
	$.ajax({
		type: "POST",
		url: "<{:U('Home/Template/set_word_list')}>",
		data: "page="+page,
		dataType:'json',
		success: function(msg){
			if(msg.status == '1'){
				var html = '';
				for(var i  in  msg.data){
					html +='<div class="top-border-box" style="margin-bottom:10px;">';

					html += '<a class="blue-link text-center pd-tb-5" href="';
					if(msg.data[i].type == '1'){
						html += '/index.php/Home/template/set_picture/tid/'+msg.data[i].id+'.html';
					}else if(msg.data[i].type == '2'){
						html += '/index.php/Home/template/video_display/tid/'+msg.data[i].id+'.html';
					}else if(msg.data[i].type == '4'){
						html += '/index.php/Home/template/set_picture/tid/'+msg.data[i].id+'.html';
					}else if(msg.data[i].type == '5'){
						html += '/index.php/Home/template/set_picture/tid/'+msg.data[i].id+'.html';
					}else{
						html += '/index.php/Home/template/set_word/tid/'+msg.data[i].id+'.html';
					}
					html += '">';
					if (msg.data[i].type == '1') {
						html += '<div style="width:80px; float:left;"><img style="width:100%; vertical-align: middle;" src="';
						html += msg.data[i].thumb;
						html += '" ></div>';
					};
					html += msg.data[i].title;
					html += '<div class="clear"></div></a>';

					html +='<div class="grey-hr"></div>';
					html +='<div class="btn-right pd-tb-10">';
					html +='<div class="type-tag">'+type_list[msg.data[i].type]+'</div>';
					html +='<a class="btn_l" href="javascript:void(0)" data-tid ="'+msg.data[i].id+'" onclick="delete_ad(this)">删除</a>';
					if(msg.data[i].type == '1'){
						html += '<a class="btn_l" href="/index.php/Home/template/set_picture/tid/'+msg.data[i].id+'.html" style="margin-left:4px">修改</a>';
					}else if(msg.data[i].type == '2'){
						html += '<a class="btn_l" href="/index.php/Home/template/video_display/tid/'+msg.data[i].id+'.html" style="margin-left:4px">修改</a>';
					}else if(msg.data[i].type == '4'){
						html += '<a class="btn_l" href="/index.php/Home/template/set_picture/tid/'+msg.data[i].id+'.html" style="margin-left:4px">修改</a>';
					}else if(msg.data[i].type == '5'){
						html += '<a class="btn_l" href="/index.php/Home/template/set_picture/tid/'+msg.data[i].id+'.html" style="margin-left:4px">修改</a>';
					}else{
						html += '<a class="btn_l" href="/index.php/Home/template/set_word/tid/'+msg.data[i].id+'.html" style="margin-left:4px">修改</a>';
					}
					html +="</div>";
					html +='</div>';
				}
				page = parseInt(page) + 1;
				$('#page').val(page);
				$('#loadding').before(html);
				// layer.closeAll(); //关闭进度条
				loadObj.hide();
			}else{
				$('#page').val('-1');
				// layer.closeAll(); //关闭进度条
				loadObj.hide();
			}
		}
	});
}


	function delete_ad(obj){
		
		var id = $(obj).attr('data-tid');
		layer.open({
			content: '您确定删除广告吗？',
			btn: ['确认', '取消'],
			shadeClose: false,
			yes: function(){
				$.ajax({
					type: "POST",
					url: "<{:U('Home/Template/set_word_delete')}>",
					data: "id="+id,
					success: function(msg){
						if(msg.status == '1'){
							layer.open({
								content:'广告删除成功',
								btn: ['确认'],
								yes:function(){
								   window.location.reload();
								}
							});
						}else{
							layer.open({
								content:msg.msg
							});
						}
					}
				});
			}
		});
		
		
	}
</script>